<script setup lang="ts">
import Title from './Title.vue';
import { ref, onMounted } from 'vue';
import { init } from '../echarts-utils';
import type { ECOption } from '../echarts-utils';

const chart = ref<HTMLElement>();

function initChart() {
  const myChart = init(chart.value);
  myChart.setOption({
    tooltip: {
      trigger: 'item'
    },
    legend: {
      orient: 'vertical',
      top: '10%',
      right: '10%',
      textStyle: {
        color: '#fff'
      }
    },
    series: [
      {
        name: '年龄比例',
        type: 'pie',
        radius: ['40%', '70%'],
        right: 100,
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: 'transparent',
          borderWidth: 2
        },
        label: {
          show: true,
          position: 'inside',
          formatter: '{c}%',
          fontSize: 8,
          color: '#fff'
        },
        emphasis: {
          label: {
            show: true,
            fontSize: 40,
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: false
        },
        data: [
          { value: 10, name: '10岁以下' },
          { value: 8, name: '10~18岁' },
          { value: 18, name: '18~30岁' },
          { value: 24, name: '30~40岁' },
          { value: 20, name: '40~60岁' },
          { value: 20, name: '60岁以上' }
        ]
      }
    ]
  } as ECOption);
}

onMounted(() => {
  initChart();
});
</script>

<template>
  <div class="age fit column">
    <Title title="年龄比例"></Title>
    <div ref="chart" class="chart col"></div>
  </div>
</template>

<style scoped lang="scss">
.age {
  background: url(../images/dataScreen-main-lb.png) no-repeat;
}
</style>
